package com.lap.framework.common.tool;

import java.math.BigDecimal;
import java.math.RoundingMode;
import lombok.experimental.UtilityClass;

/**
 * 汇率转换到整数工具
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
@UtilityClass
public class VatRateStrategy {

  private static final BigDecimal DENOMINATOR = BigDecimal.valueOf(10000);

  public static Integer multiply(Double value) {
    if (value == null) {
      return 0;
    }
    return BigDecimal.valueOf(value)
        .multiply(DENOMINATOR)
        .setScale(0, RoundingMode.HALF_UP)
        .intValue();
  }

  public static Double divide(Integer value) {
    if (value == null) {
      return 0.0;
    }
    return BigDecimal.valueOf(value).divide(DENOMINATOR, 4, RoundingMode.HALF_UP).doubleValue();
  }
}
